package com.chen.blog.exception;

import com.chen.blog.utils.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author cgj
 * @date 1/24/25 9:42 AM
 */
//@ControllerAdvice
//@ResponseBody
//    异常统一处理
@RestControllerAdvice   // 等价于前面的两个
public class BlogExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Result exHandler(Exception e){
        e.printStackTrace(); //  方便后端排查
//        给前端提示信息
        return  Result.fail().message(e.getMessage());
    }
}
